//
//  FZQChaseProgramViewController.m
//  BiliBiliDemo
//
//  Created by IMAC on 16/4/20.
//  Copyright © 2016年 XDH. All rights reserved.
//

#import "FZQChaseProgramViewController.h"

#import "FZQProgramCell.h"

#import "FZQProgram.h"

#import "BiliBiliDynamicHeaderView.h"

#import "MBProgressHUD+XMG.h"

@interface FZQChaseProgramViewController ()

/** programs数组 */
@property (nonatomic, strong) NSMutableArray *programs;

@end



@implementation FZQChaseProgramViewController

#pragma mark - lazy load
-(NSMutableArray *)programs
{
    if (!_programs) {
        
        _programs = [NSMutableArray array];
    }
    return _programs;
}



#pragma mark - life cycle
-(void)viewDidLoad {
    [super viewDidLoad];
    
    /** 初始化tableView */
    [self setUptableView];
    
    /****** 弹出蒙板 *****/
    [MBProgressHUD showMessage:@"努力加载中。。。" toView:self.view];
    
    /****** 收回蒙板 *****/
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [MBProgressHUD hideHUDForView:self.view];
    });
    
    //网络请求，请求页面数据，并添加到programs中
    
}

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    
    //弹出蒙板，显示加载数据
    
    //判断网络情况
    
    //网络情况不好，或者programs没有数据
    
    //显示需要下拉刷新
    
    //网络情况好，重新刷新数据
    
}

#pragma mark - setup 设置控件
/** 设置tableView */
-(void)setUptableView
{   
    //设置tableView
    self.tableView.rowHeight = 100;//行高
    self.tableView.backgroundColor = [UIColor whiteColor];//背景颜色
    
    //设置头部视图
    self.tableView.tableHeaderView = [BiliBiliDynamicHeaderView dynamicHeaderView];
}


#pragma mark - <UITableViewDataSource>
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.programs.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //生成cell
    FZQProgramCell *cell = [FZQProgramCell cellWithTableView: tableView style:UITableViewCellStyleSubtitle];
    
    //设置cell
    //    cell.program = self.programs[indexPath.row];
    
    /** 设置cell辅助视图 */
    [self setupAccessoryView:cell];
    
    return cell;
}

/** 设置辅助视图 */
-(void)setupAccessoryView:(FZQProgramCell *)cell
{   
    //创建按钮
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    
    //设置文字
    [btn setTitle:@"追番" forState:UIControlStateNormal];
    [btn setTitleColor:HPColorPink forState:UIControlStateNormal];
    
    //设置layer层
    btn.layer.cornerRadius = 5;
    btn.layer.borderWidth = 1;
    btn.layer.borderColor = HPColorPink.CGColor;
    
    //为按钮增加方法
    [btn addTarget:self action:@selector(chaseProgram:) forControlEvents:UIControlEventTouchUpInside];
    
    //按钮自适配
    btn.bounds = CGRectMake(0, 0, 55, 30);
    
    //设置辅助视图按按钮
    cell.accessoryView = btn;
}

#pragma mark - <UITableViewDelegate>


#pragma mark - skip
/* 追番 */
- (void)chaseProgram:(FZQProgramCell *)cell
{
    
}

@end